package com.kuang.controller;

import com.kuang.pojo.AstLocalOpenWell;
import com.kuang.pojo.AstLocalOpeningWell;
import com.kuang.service.asset.AstLocalOpenWellService;
import com.kuang.service.asset.AstLocalOpeningWellService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
public class AstLocalOpeningWellController {

    @Resource
    AstLocalOpeningWellService astLocalOpeningWellService;

    /**
     * 设备端本地关井实时数据 全部数据
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstLocalOpeningWells")
    public String getAstLocalOpeningWells(Model model) {
        List<AstLocalOpeningWell> astLocalOpeningWells = astLocalOpeningWellService.selectAll();
        model.addAttribute("datas", astLocalOpeningWells);
        model.addAttribute("device_code", "");
        model.addAttribute("ver", "");
        return "mqtt/ast_local_opening_well_list";
    }

    /**
     * 设备端本地关井实时数据 通过条件
     *
     * @param model
     * @return
     */
    @PostMapping("getAstLocalOpeningWellsByExample")
    public String getAstLocalOpeningWellsByExample(AstLocalOpeningWell astLocalOpeningWell, Model model) {
        List<AstLocalOpeningWell> astLocalOpeningWells = astLocalOpeningWellService.selectAllByExample(astLocalOpeningWell);
        model.addAttribute("datas", astLocalOpeningWells);
        model.addAttribute("device_code", astLocalOpeningWell.getDevice_code());
        model.addAttribute("ver", astLocalOpeningWell.getVer());
        return "mqtt/ast_local_opening_well_list";
    }

    /**
     * 获取设备信息通过id
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstLocalOpeningWellById/{id}")
    public String getAstLocalOpeningWellById(@PathVariable("id") String id, Model model) {
        AstLocalOpeningWell astLocalOpeningWell = new AstLocalOpeningWell();
        astLocalOpeningWell.setAst_local_opening_well_id(id);
        List<AstLocalOpeningWell> astLocalOpeningWells = astLocalOpeningWellService.selectAllByExample(astLocalOpeningWell);
        model.addAttribute("data", astLocalOpeningWells.get(0));
        return "mqtt/ast_local_opening_well_from";
    }

}
